package com.example.projectgamefinal1;

import java.util.ArrayList;
import java.util.List;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

public class Energidesign extends Activity{

	private Spinner spinner1, spinner2, spinner3;
	private Button btnSubmit1;
	private Button btnSubmit2, btnSubmit3;
	private ListCheck listCh;
	public static List<String> list = new ArrayList<String>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Intent intent = getIntent();
		String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
		
		setContentView(R.layout.energidesign_page);
		addListenerOnButton();
		addListenerOnSpinnerItemSelection();
		// Show the Up button in the action bar.
		//setupActionBar();
	}

	public void addListenerOnSpinnerItemSelection() {
		spinner1 = (Spinner) findViewById(R.id.redBricksList);
		spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
		spinner2 = (Spinner) findViewById(R.id.yellowBricksList);
		spinner2.setOnItemSelectedListener(new CustomOnItemSelectedListener());
		spinner3 = (Spinner) findViewById(R.id.greenBricksList);
		spinner3.setOnItemSelectedListener(new CustomOnItemSelectedListener());
	}

	// get the selected dropdown list value
	public void addListenerOnButton() {

		spinner1 = (Spinner) findViewById(R.id.redBricksList);
		spinner2 = (Spinner) findViewById(R.id.yellowBricksList);
		spinner3 = (Spinner) findViewById(R.id.greenBricksList);
		btnSubmit1 = (Button) findViewById(R.id.addBrickBtn1);
		btnSubmit1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (spinner1.getSelectedItem().toString() != "-") {
					if (listCh.checkOtherLists(spinner1.getSelectedItem().toString())) {
						list.add(spinner1.getSelectedItem().toString());

						if (list.contains(spinner1.getSelectedItem().toString())) {
							Toast.makeText(
									Energidesign.this,
									"OnClickListener : "
											+ "\nSpinner 1 : "
											+ String.valueOf(spinner1
													.getSelectedItem()
													+ " has been added to the category"),
									Toast.LENGTH_SHORT).show();
						}
					} else
						Toast.makeText(
								Energidesign.this,
								"The item has already been added to the category!",
								3).show();
				} else
					Toast.makeText(Energidesign.this, "Please select an item!", 3).show();
			}

		});
		btnSubmit2 = (Button) findViewById(R.id.addBrickBtn2);
		btnSubmit2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (spinner2.getSelectedItem().toString() != "-") {
					if  (listCh.checkOtherLists(spinner2.getSelectedItem().toString())) {
						list.add(spinner2.getSelectedItem().toString());

						if (list.contains(spinner2.getSelectedItem().toString())) {
							Toast.makeText(
									Energidesign.this,
									"OnClickListener : "
											+ "\nSpinner 2 : "
											+ String.valueOf(spinner2
													.getSelectedItem()
													+ " has been added to the category"),
									Toast.LENGTH_SHORT).show();
						}
					} else
						Toast.makeText(
								Energidesign.this,
								"The item has already been added to the category!",
								3).show();
				} else
					Toast.makeText(Energidesign.this, "Please select an item!", 3).show();
			}

		});
		btnSubmit3 = (Button) findViewById(R.id.addBrickBtn3);
		btnSubmit3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (spinner3.getSelectedItem().toString() != "-") {
					if  (listCh.checkOtherLists(spinner3.getSelectedItem().toString())) {
						list.add(spinner3.getSelectedItem().toString());

						if (list.contains(spinner3.getSelectedItem().toString())) {
							Toast.makeText(
									Energidesign.this,
									"OnClickListener : "
											+ "\nSpinner 3 : "
											+ String.valueOf(spinner3
													.getSelectedItem()
													+ " has been added to the category"),
									Toast.LENGTH_SHORT).show();
						}
					} else
						Toast.makeText(
								Energidesign.this,
								"The item has already been added to the category!",
								3).show();
				} else
					Toast.makeText(Energidesign.this, "Please select an item!", 3).show();
			}

		});
	}

	/**
	 * Set up the {@link android.app.ActionBar}, if the API is available.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setupActionBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
